package com.biglead.mini.controller;

import com.biglead.common.pojo.CommonResult;
import com.biglead.mini.pojo.PmsProduct;
import com.biglead.mini.result.HomeContentResult;
import com.biglead.mini.service.HomeService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 首页内容管理
 */
@Slf4j
@RestController
@RequestMapping("/home")
public class HomeController {
    @Autowired
    private HomeService homeService;

    @ApiOperation("首页内容信息展示")
    @RequestMapping(value = "/content", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<HomeContentResult> content() {
        HomeContentResult contentResult = homeService.content();
        return CommonResult.success(contentResult);
    }


    @ApiOperation("分页获取人气推荐商品")
    @RequestMapping(value = "/hotProductList", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<PmsProduct>> hotProductList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                         @RequestParam(value = "pageSize", defaultValue = "6") Integer pageSize) {
        List<PmsProduct> productList = homeService.hotProductList(pageNum,pageSize);
        return CommonResult.success(productList);
    }

    @ApiOperation("获取商品总数")
    @RequestMapping(value = "/goodsCount", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<Integer> goodsCount() {
        Integer goodsCount = homeService.goodsCount();
        return CommonResult.success(goodsCount);
    }
}
